<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) 2023 https://inphp.cc All rights reserved.
// | Licensed ( https://opensource.org/licenses/MIT )
// | Author: 幺月儿(https://gitee.com/lulanyin) Email: inphp@qq.com
// +----------------------------------------------------------------------
// | 账号API
// +----------------------------------------------------------------------
namespace app\admin\http\api;

use Inphp\Core\Db\Redis;
use Inphp\Core\Object\Message;
use Inphp\Core\Services\Http\Cookie;

#[\app\admin\attributes\auth] class user
{
    /**
     * 账户数据
     * @var array
     */
    public array $user = [];

    /**
     * 登陆TOKEN
     * @var string
     */
    public string $token = "";

    /**
     * 获取授权账户信息
     * @return array
     */
    public function index(): array
    {
        return [
            "uid"           => $this->user["uid"],
            "parentUid"     => $this->user["parentUid"] ?? 0,
            "parentsUid"    => $this->user["parentsUid"] ?? null,
            "username"      => $this->user["username"] ?? null,
            "countryCode"   => $this->user["countryCode"] ?? 86,
            "phone"         => $this->user["phone"] ?? null,
            "nickname"      => $this->user["nickname"] ?? null,
            "face"          => $this->user["face"] ?? null,
            "registerTime"  => $this->user["registerTime"] ?? date("Y-m-d H:i:s"),
            "ip"            => $this->user["ip"] ?? null,
            "state"         => $this->user["state"] ?? 1,
            "admin"         => $this->user["admin"] ?? 0
        ];
    }

    /**
     * 退出登陆
     * @return Message
     */
    public function logout(): Message
    {
        @Redis::del("Token_{$this->token}");
        Cookie::delete("token");
        return httpMessage(0, "账户已注销登陆状态");
    }
}